/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import com.sun.lwuit.Form;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.layouts.BorderLayout;
import view.additional.CellItem;
import view.additional.ThumbList;
import view.additional.TickerRenderer;

/**
 *
 * @author Kvest
 */
public class MelodySearchForm extends Form implements ActionListener
{
    public static final int OK_ID = 1;
    public static final int CANCEL_ID = 2;

    private Command cancel;
    private Command ok;
    private FormAction listener;

    //Список 
    private ThumbList items;

    public MelodySearchForm(FormAction listener)
    {
        super("Файлы");
        this.listener = listener;

        init();
    }

    private void init()
    {
        setLayout(new BorderLayout());
        setScrollable(false);

        addCommandListener(this);

        cancel = new Command("Отмена", CANCEL_ID);
        addCommand(cancel);

        ok = new Command("Ok", OK_ID);
        addCommand(ok);

        //Создаем и настраиваем список
        items = new ThumbList();
        items.setSelectCommandText("");
        items.setFixedSelection(ThumbList.FIXED_NONE_CYCLIC);
        TickerRenderer render = new TickerRenderer();
        render.getStyle().setPadding(Component.BOTTOM, 0);
        render.getStyle().setPadding(Component.TOP, 0);
        items.setRenderer(render);
        items.getStyle().setPadding(Component.BOTTOM, 0);
        items.getStyle().setPadding(Component.TOP, 0);
        addComponent(BorderLayout.CENTER,items);
    }

    public void clear()
    {
        while (items.size() > 0)
        {
            items.getModel().removeItem(0);
        }
    }

    public void add(CellItem item)
    {
        items.getModel().addItem(item);
    }

    public CellItem getSelectedItem()
    {
        return (CellItem)items.getSelectedItem();
    }

    public void actionPerformed(ActionEvent evt)
    {
        if (listener != null)
        {
            listener.commandAction(evt.getCommand().getId());
        }
    }
}
